/*********************************************************************************************************
**
**                                   GJB 标准测试集
**
**                               Copyright All Rights Reserved
**
**--------------文件信息--------------------------------------------------------------------------------
**
** 文   件   名: gjb_S0100904GN_2.c
**
** 文件创建日期: 2021 年 1 月 22 日
**
** 描        述: 使用条件变量同时唤醒一个或者多个等待任务/进程功能测试
*********************************************************************************************************/
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>

// #include "gjb.h"

// int gjb_S0100904GN_2(int argc, char **argv)
int main(int argc, char **argv)
{
    pthread_condattr_t  condattr;
    pthread_cond_t      cond;
    int                 rc,fail=0;

    /*
     * Initialize a condition variable attribute object
     */
    if ((rc = pthread_condattr_init(&condattr)) != 0) {
        printf("Error at pthread_condattr_init(), rc=%d\n",rc);
        goto __errno_handle;
    }

    /*
     * Initialize cond with the default condition variable attribute
     */
    if ((rc = pthread_cond_init(&cond,&condattr)) != 0) {
        printf("Fail to initialize cond, rc=%d\n",rc);
        goto __errno_handle;
    }

    /*
     * Destroy the condition variable attribute object
     */
    if ((rc = pthread_condattr_destroy(&condattr)) != 0) {
        printf("Error at pthread_condattr_destroy(), rc=%d\n",rc);
        goto __errno_handle;
    }

    /*
     * Destroy cond
     */
    if ((rc = pthread_cond_destroy(&cond)) != 0) {
        printf("Fail to destroy cond, rc=%d\n",rc);
        printf("Test FAILED\n");

        goto __errno_handle;
    }

    rc = pthread_cond_signal(&cond);
    if (rc == EINVAL) {
        printf("test pass when the cond is not exist .pthread_cond_signal return EINVAL\n");

    } else {
        printf("test failed when the cond is not exist.pthread_cond_signal should return EINVAL,but return %d\n",rc);
        fail = 1;
    }


    rc = pthread_cond_signal(NULL);
    if (rc == EINVAL) {
        printf("test NULL pass.pthread_cond_signal return EINVAL\n");

    } else {
        printf("test failed:pthread_cond_signal should return EINVAL,but return %d",rc);
        fail = 1;
    }

    if (fail == 1) {
        printf("Test failed.\n");
        goto __errno_handle;

    } else {
        printf("Test pass\n");
    }

    printf("<RSLT>..................................................[(0)]\n \n \n");

    return  (0);  

__errno_handle:
    printf("<RSLT>..................................................[(-1)]\n \n \n");
    return  (-1);   

}
